package com.songtech.server.task;

import org.springframework.stereotype.Component;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Create By YINN on 2018/4/16 11:10
 * Description :
 */

public class ServerTimer extends Timer{

    private TimerTask timerTask;

    private long delay;

    private long period;

    /**
     * @param timerTask 任务
     * @param delay 延迟(1s 就是1000L，单位毫秒)
     * @param period 间隔(1s 就是1000L，单位毫秒)
     */
    public ServerTimer(TimerTask timerTask, long delay, long period) {
        this.timerTask = timerTask;
        this.delay = delay;
        this.period = period;
    }

    /**
     * Created by YINN on 2018/4/16 11:15.
     * @Description : timer启动方法
     * @Result :
     */
    public void startTimer(){

        this.schedule(timerTask, delay, period);// 1秒后启动任务,以后每隔3秒执行一次线程

    }

}
